# Maintainer: Jonas Witschel <diabonas@archlinux.org>
pkgname=pdftk
pkgver=3.3.3
pkgrel=2
pkgdesc='Command-line tool for working with PDFs'
arch=('any')
url='https://gitlab.com/pdftk-java/pdftk'
license=('GPL')
depends=('bcprov' 'java-commons-lang' 'java-runtime-headless' 'sh')
makedepends=('ant' 'strip-nondeterminism')
checkdepends=('java-hamcrest' 'junit' 'junit-system-rules' 'poppler')
optdepends=('bcprov: support for AES encrypted and signed PDF documents'
            'java-commons-lang: burst, dump_data, dump_data_fields and update_info operation support')
source=("$url/-/archive/v$pkgver/$pkgname-v$pkgver.tar.bz2" 'pdftk.sh')
sha512sums=('48173d0c4698bc984221b56dff3e6434df7cf144dddfdbf684f8fa28b9eacfd0ebf9ebca0b87df3f9534a1ed13caa4c0866bd3e7a8cd06a21b46dfaedda9ea21'
            'd9b83165027de5cfe7b452cd9080384f5bd36e58ed0fd041a737d37f1a843fc75588fbac0f93fc77fb6ae1826c7df335a8b68db8265b707c4e909eed1c7bed82')

prepare() {
	cd "$pkgname-v$pkgver"
	mkdir lib
	ln -s /usr/share/java/{bcprov/bcprov,commons-lang/commons-lang,hamcrest-core,junit,junit-system-rules/system-rules}.jar lib
	# No need for code coverage reports during tests
	sed -ri '/<\/?jacoco:coverage>/d' build.xml
}

build() {
	cd "$pkgname-v$pkgver"
	ant clean jar

	# Timestamps in JAR files generated by Ant do not honour SOURCE_DATE_EPOCH
	# (https://bz.apache.org/bugzilla/show_bug.cgi?id=61269)
	strip-nondeterminism --timestamp "$SOURCE_DATE_EPOCH" build/jar/pdftk.jar
}

check() {
	cd "$pkgname-v$pkgver"
	ant test-run
}

package() {
	cd "$pkgname-v$pkgver"
	install -Dm644 build/jar/pdftk.jar -t "$pkgdir/usr/share/java/$pkgname"
	install -Dm644 pdftk.1 -t "$pkgdir/usr/share/man/man1"
	install -Dm755 "$srcdir/pdftk.sh" "$pkgdir/usr/bin/pdftk"
}
